<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<style>
.a1 #b1 { background-color: green }
.a2 div + #b2 { background-color: green }
</style>
<div id="t1">
    <div></div>
    <div id="b1"></div>
</div>
<div id="t2">
    <div></div>
    <div id="b2"></div>
</div>
<script>
description("Check that targeted class invalidation works for id selectors.");

var transparent = "rgba(0, 0, 0, 0)";
var green = "rgb(0, 128, 0)";

var b1 = document.getElementById("b1");
var b2 = document.getElementById("b2");

shouldBe("getComputedStyle(b1, null).backgroundColor", "transparent");
shouldBe("getComputedStyle(b2, null).backgroundColor", "transparent");

document.body.offsetTop; // Force style recalc.

document.getElementById("t1").className = "a1";
if (window.internals)
    shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "1");
shouldBe("getComputedStyle(b1, null).backgroundColor", "green");

document.body.offsetLeft; // force style recalc.

document.getElementById("t2").className = "a2";
if (window.internals)
    shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "1");
shouldBe("getComputedStyle(b2, null).backgroundColor", "green");

</script>
